var detectCycle = function(head) {
    if (!head || !head.next)
        return null;
    let slow = head.next;
    let fast = head.next.next;
    while (fast !== slow && fast && fast.next) {
        slow = slow.next;
        fast = fast.next.next;
        if (slow === fast) {
            slow = head;
            while (slow !== fast) {
                slow = slow.next;
                fast = fast.next;
            }
            return slow;
        }
    }
    return null;
}


